#include "gobang.h"
#include "ui_gobang.h"
#include <QPainter>
#include <QPen>

str_usrdata m_usrdata;

Gobang::Gobang(QWidget *parent) : QWidget(parent), ui(new Ui::Gobang)
{
    ui->setupUi(this);
    this->setWindowTitle(GOBANGNAME);

    setWindowFlag(Qt::FramelessWindowHint);
    setAttribute(Qt::WA_TranslucentBackground);
    this->setMouseTracking(true);

    m_nSteps = 0;           //总步数
    m_bFristStep = true;      //执子方
    m_bNextStep = true;
    for (int i = 0; i < 15; i++)
    {
        for (int j = 0; j < 15; j++)
        {
            m_nStepdatas[i][j][0] = 0;
            m_nStepdatas[i][j][1] = 0;
            m_nNetStepdatas[i][j][0] = 0;
            m_nNetStepdatas[i][j][1] = 0;
        }
    }
    m_nUInum = 1;
    m_nroomusr[0] = 0;
    m_nroomusr[1] = 0;

    m_bNetFristStep = true;//经典模式执子方

    //g_nStepdata[225][225] = {0};
    m_nmoveX = 0;
    m_nmoveY = 0;
    m_nOutcome = 0;
    m_nroomsnum = 1;//房间页数第一页

    m_bConfirmState = false;
    m_bWinMovestate = false;
    m_bmovestate = false;

    m_nNetSteps = 0;
    m_bNetFristStep = true;
    m_bNetNextStep = true;
    m_bNetStartgame = false;
    m_nNetOutcome = 0;
    m_bNetCallover = false;

    QPalette palette_write;
    palette_write.setColor(QPalette::WindowText, Qt::white);
    //font_24.setPointSize(24);//随系统字体大小而改变
    font_30.setPixelSize(30);//不随系统字体大小改变
    font_30.setFamily("SimHei");//黑体

    //font_16.setPointSize(16);
    font_20.setPixelSize(20);
    font_20.setFamily("SimHei");

    label_btnA.setParent(this);
    label_btnA.setPalette(palette_write);
    label_btnA.setText("单机模式");
    label_btnA.setFont(font_30);
    label_btnA.resize(140, 40);
    label_btnA.move(695, 320);

    label_btnB.setParent(this);
    label_btnB.setPalette(palette_write);
    label_btnB.setText("联机模式");
    label_btnB.setFont(font_30);
    label_btnB.resize(140, 40);
    label_btnB.move(695, 420);

    label_btnC.setParent(this);
    label_btnC.setPalette(palette_write);
    label_btnC.setText("退    出");
    label_btnC.setFont(font_30);
    label_btnC.resize(140, 40);
    label_btnC.move(695, 520);

    //用户名
    m_lloginname->setParent(this);
    m_lloginname->setFont(font_20);
    m_lloginname->resize(180, 30);
    m_lloginname->move(220, 260);
    m_lloginname->hide();

    //密码
    m_lloginpass->setParent(this);
    m_lloginpass->setFont(font_20);
    m_lloginpass->resize(180, 30);
    m_lloginpass->move(220, 320);
    m_lloginpass->setEchoMode(QLineEdit::Password);
    m_lloginpass->hide();

    //确认密码
    m_lloginpasses->setParent(this);
    m_lloginpasses->setFont(font_20);
    m_lloginpasses->resize(180, 30);
    m_lloginpasses->move(220, 380);
    m_lloginpasses->setEchoMode(QLineEdit::Password);
    m_lloginpasses->hide();

    //房间玩家名
    for (int i = 0; i < 36; i++)
    {
        label_rooms[i].setParent(this);
        label_rooms[i].setFont(font_20);
        label_rooms[i].setAlignment(Qt::AlignHCenter);
        label_rooms[i].setAlignment(Qt::AlignCenter);
        if (i%3 == 0)
        {
            //label_rooms[i].setText("桌");
            label_rooms[i].resize(40, 45);
        }
        else
        {
            label_rooms[i].setText("空");
            label_rooms[i].resize(130, 40);
        }
        label_rooms[i].hide();
    }
    for (int j = 0; j < 3; j++)
    {
        for (int i = 0; i < 4; i++)
        {
            //label_rooms[(4*j+i)*3].setText(QString("%1桌").arg(4*j+i+1));
            label_rooms[(4*j+i)*3].move(40 + i*140, 120 + j*180);//房间名
            label_rooms[(4*j+i)*3 + 1].move(55 + i*140, 60 + j*180);//玩家A
            label_rooms[(4*j+i)*3 + 2].move(55 + i*140, 180 + j*180);//玩家B
        }
    }

    tcpsocket = NULL;
    m_bTCPstate = false;
    tcpsocket = new QTcpSocket(this);

    connect(tcpsocket, &QTcpSocket::connected, this, Gobang::tcpconnect);
    connect(tcpsocket, &QTcpSocket::disconnected, this, Gobang::tcpdisconnect);

    QString ip = QString(TCPSERVICE_IP);
    qint16 port = PORT;
    tcpsocket->connectToHost(QHostAddress(ip), port);//连接服务器

    m_nRunTimems = 0;
    m_nRunTimes = 0;
    m_nRunTimeh = 0;

    timer_100ms = new QTimer(this);
    connect(timer_100ms, SIGNAL(timeout()), this, SLOT(RunTimer()));
    timer_100ms->start(100);
}

Gobang::~Gobang()
{
    delete ui;
}

// 连接服务器
void Gobang::tcpconnect()
{
    m_bTCPstate = true;//如果连接成功
    connect(tcpsocket, &QTcpSocket::readyRead, this, Gobang::tcpreaddata);
    // QString senddata = QString("OK@");
    // char *sendchar = senddata.toUtf8().data();
    // tcpsocket->write(sendchar);
    update();//更新显示状态
}

// 服务器断开
void Gobang::tcpdisconnect()
{
    m_bTCPstate = false;
    update();
    QString ip = QString(TCPSERVICE_IP);
    qint16 port = PORT;
    tcpsocket->connectToHost(QHostAddress(ip), port);//连接服务器
}

// 读取TCP通讯字节
void Gobang::tcpreaddata()
{
    QByteArray array = tcpsocket->readAll();
    QString readdata = array;
    QString keywords = readdata.section('@', 0, 0);
    if (keywords == "namesame")
    {
        if (m_nUInum == 91)
        {
            QMessageBox m_r(this);
            m_r.setWindowTitle("提示");
            m_r.setText("该用户名已被占用，请更改用户名");
            m_r.exec();
        }
    }
    else if (keywords == "registerOK")
    {
        if (m_nUInum == 91)
        {
            QMessageBox m_r(this);
            m_r.setWindowTitle("提示");
            m_r.setText("注册成功！");
            m_r.exec();
            //注册成功后便直接进入登录界面
            m_nUInum = 90;//登录
            label_btnA.setText("登    录");
            label_btnB.setText("忘记密码");
            label_btnC.setText("返    回");
            m_lloginname->show();
            m_lloginpass->show();
            m_lloginpasses->hide();
            m_lloginpass->setText("");
            m_lloginpasses->setText("");
        }
    }
    else if (keywords == "loginOK")//登录成功
    {
        m_usrdata.usrname = m_lloginname->text();
        m_usrdata.passwd = m_lloginpass->text();
        QMessageBox m_r(this);
        m_r.setWindowTitle("提示");
        m_r.setText("登录成功！");
        m_r.exec();

        m_lloginname->hide();
        m_lloginpass->hide();
        m_lloginpasses->hide();

        m_nUInum = 30;
        label_btnA.setText("经典模式");
        label_btnB.setText("娱乐模式");
        label_btnC.setText("返    回");

        update();
    }
    else if (keywords == "loginnoname")
    {
        QMessageBox m_r(this);
        m_r.setWindowTitle("提示");
        m_r.setText("登录失败，无此用户名！");
        m_r.exec();
    }
    else if (keywords == "loginnopass")
    {
        QMessageBox m_r(this);
        m_r.setWindowTitle("提示");
        m_r.setText("登录失败，密码错误！");
        m_r.exec();
    }
    else if (keywords == "loginyet")
    {
        QMessageBox m_r(this);
        m_r.setWindowTitle("提示");
        m_r.setText("您已登录");
        m_r.exec();
    }
    else if (keywords == "rooms")
    {
        QString backdata = readdata.mid(keywords.length() + 1);
        for (int i = 0; i < 12; i++)
        {
            if ((m_nroomsnum-1)*12+i+1 == backdata.section(' ', i*3, i*3).toInt())
            {
                roomsuser[i*2] = backdata.section(' ', i*3+1, i*3+1);
                roomsuser[i*2+1] = backdata.section(' ', i*3+2, i*3+2);
                if (roomsuser[i*2].isEmpty())
                {
                    roomsuser[i*2] = "NULL";
                }
                if (roomsuser[i*2+1].isEmpty())
                {
                    roomsuser[i*2+1] = "NULL";
                }
                label_rooms[i*3+1].setText(roomsuser[i*2]);
                label_rooms[i*3+2].setText(roomsuser[i*2+1]);
                if (label_rooms[i*3+1].text() == "NULL")
                {
                    label_rooms[i*3+1].setStyleSheet("color:#aaaaaa;");
                }
                else
                {
                    label_rooms[i*3+1].setStyleSheet("color:#000000;");
                }
                if (label_rooms[i*3+2].text() == "NULL")
                {
                    label_rooms[i*3+2].setStyleSheet("color:#aaaaaa;");
                }
                else
                {
                    label_rooms[i*3+2].setStyleSheet("color:#000000;");
                }
            }
        }
        update();
    }
    else if (keywords == "inroom")//进入房间
    {
        QString backdata = readdata.mid(keywords.length() + 1);
        //qDebug() << "inroom backdata:" << backdata;
        m_usrdata.room = backdata.section(' ', 0, 0).toInt();
        for (int i = 0; i < 36; i++)
        {
            label_rooms[i].hide();
        }
        m_nUInum = 33;

        label_btnA.setText("");
        label_btnB.setText("");
        label_btnC.setText("退出房间");

        //qDebug() << "inroom backdata = " << backdata;
        m_sroomuser[0] = backdata.section(' ', 1, 1);//第一个玩家
        m_nroomusr[0] = backdata.section(' ', 2, 2).toInt();//玩家准备情况
        m_sroomuser[1] = backdata.section(' ', 3, 3);//第二个玩家
        m_nroomusr[1] = backdata.section(' ', 4, 4).toInt();//第二个玩家准备情况
        uchar myseat = backdata.section(' ', 5, 5).toInt();// 获取自身位置
        //qDebug() << "my seat: " << myseat;
        if (myseat >= 4)//判断是否为旁观玩家
        {
            label_btnA.setText("观 战 中");
            myseat = myseat - 1;
            m_usrdata.place = myseat;
            QString strchess = backdata.section(' ', 6, 6);
            m_nNetSteps = 0;
            //qDebug() << "OK1";
            for (int i = 0; i < 15; i++)
            {
                for (int j = 0; j < 15; j++)
                {
                    int chess = strchess.left(1).toInt();
                    m_nNetStepdatas[i][j][0] = chess;
                    strchess = strchess.mid(1);
                    if (m_nNetStepdatas[i][j][0] != 0)
                    {
                        m_nNetSteps++;
                        //qDebug() << "ok2";
                    }
                }
            }
            NetOutcome();
        }
        else if (myseat == 0)
        {
            label_btnA.setText("准    备");
            myseat = 1;
            m_usrdata.place = 1;
        }
        else if (myseat == 2)
        {
            label_btnA.setText("准    备");
            m_usrdata.place = 2;
        }
        //qDebug() << "my place: " << m_usrdata.place;
        m_usrdata.ready = 0;
        update();
    }
    else if (keywords == "outroomOK")
    {
        for (int i = 0; i < 36; i++)
        {
            label_rooms[i].show();
        }
        QString senddata = QString("viewrooms@%1").arg(m_nroomsnum);
        char *sendchar = senddata.toUtf8().data();
        tcpsocket->write(sendchar);//发送登录信息
    }
    else if (keywords == "usrinroom")//告知有人进入房间
    {
        if (m_nUInum == 33)
        {
            QString backdata = readdata.mid(keywords.length() + 1);
            QString usrname = backdata.section(' ', 0, 0);
            int usrnum = backdata.section(' ', 2, 2).toInt();
            if (usrnum == 1)
            {
                m_sroomuser[0] = usrname;//第一个玩家
                m_nroomusr[0] = 0;
            }
            else if (usrnum == 2)
            {
                m_sroomuser[1] = usrname;//第一个玩家
                m_nroomusr[1] = 0;
            }
            update();
        }
    }
    else if (keywords == "usroutroom")//告知有人退出房间
    {
        if (m_nUInum == 33)
        {
            QString backdata = readdata.mid(keywords.length() + 1);
            QString usrname = backdata.section(' ', 0, 0);
            if (m_sroomuser[0] == usrname)
            {
                m_sroomuser[0].clear();
                m_nroomusr[0] = 0;
            }
            else if (m_sroomuser[1] == usrname)
            {
                m_sroomuser[1].clear();
                m_nroomusr[1] = 0;
            }
            update();
        }
    }
    else if (keywords == "usrready")//用户准备
    {
        if (m_nUInum == 33)
        {
            QString backdata = readdata.mid(keywords.length() + 1);
            //qDebug() << "usrready backdata = " << backdata;
            QString usrname = backdata.section(' ', 1, 1);
            int usrready = backdata.section(' ', 2, 2).toInt();
            if (m_sroomuser[0] == usrname)
            {
                m_nroomusr[0] = usrready;
            }
            else if (m_sroomuser[1] == usrname)
            {
                m_nroomusr[1] = usrready;
            }
            if (usrready == 0 && m_usrdata.usrname == usrname)
            {
                label_btnA.setText("准    备");
            }
            else if (m_usrdata.usrname == usrname)
            {
                label_btnA.setText("取消准备");
            }
            if (m_usrdata.place <= 2)
            {
                if (m_nroomusr[0] != 0 && m_nroomusr[1] != 0)
                {
                    if (m_usrdata.place == 1)
                    {
                        if (m_nroomusr[0] == 1)
                        {
                            m_bNetFristStep = true;
                        }
                        else
                        {
                            m_bNetFristStep = false;
                        }
                    }
                    else
                    {
                        if (m_nroomusr[1] == 1)
                        {
                            m_bNetFristStep = true;
                        }
                        else
                        {
                            m_bNetFristStep = false;
                        }
                    }
                    m_bNetStartgame = true;
                    m_bNetNextStep = true;  // 黑子先下
                    m_nNetSteps = 0;
                    m_nNetOutcome = 0;
                    for (int i = 0; i< 15; i++)
                    {
                        for (int j = 0; j < 15; j++)
                        {
                            m_nNetStepdatas[i][j][0] = 0;
                            m_nNetStepdatas[i][j][1] = 0;
                        }
                    }
                    label_btnA.setText("悔    棋");
                    label_btnB.setText("和    棋");
                    label_btnC.setText("认    输");
                }
            }
            update();
        }
    }
    else if (keywords == "startgame") //开始游戏
    {
        if (m_nUInum == 33)
        {
            m_bNetStartgame = true;
        }
    }
    else if (keywords == "tobang")  // 更新棋子
    {
        if (m_nUInum == 33)
        {
            QString backdata = readdata.mid(keywords.length() + 1);
            //qDebug() << "tobang: " << backdata;
            //QString username = backdata.section(' ', 0, 0);
            backdata = backdata.section(' ', 1, 1);
            int i = backdata.section(',', 0, 0).toInt();
            int j = backdata.section(',', 1, 1).toInt();
            char nextstep = backdata.section(',', 2, 2).toInt();

            if (m_nNetStepdatas[i][j][0] == 0)//判断是否已落子
            {
                if (m_nNetOutcome == 0)//判断比赛是否结束
                {
                    m_nNetSteps++;
                    if (nextstep == 1)
                    {
                        m_nNetStepdatas[i][j][0] = 1;//黑子为1
                        if (m_usrdata.place <= 2)
                        {
                            m_bNetNextStep = false;
                        }
                    }
                    else
                    {
                        m_nNetStepdatas[i][j][0] = 2;//白子为2
                        if (m_usrdata.place <= 2)
                        {
                            m_bNetNextStep = true;
                        }
                    }
                    m_nNetStepdatas[i][j][1] = m_nNetSteps;
                    NetOutcome();   // 检查比赛是否已经结束
                }
            }
            update();
        }
    }
    else if (keywords == "advundo") // 悔棋通知
    {
        //qDebug() << "advundo";
        QMessageBox m_r(this);
        //m_r.setWindowTitle("提示");
        //m_r.setText("对方请求悔棋！");
        QMessageBox::StandardButton m_infor = m_r.information(NULL, "悔棋", "对方请求悔棋", QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
        if (m_infor == QMessageBox::Yes)  // 同意悔棋
        {
            if (m_bNetFristStep == m_bNetNextStep) // '我'还没下，只悔一子
            {
                int chessA, chessB;
                if (m_bNetNextStep == true)
                {
                    m_bNetNextStep = false;
                }
                else
                {
                    m_bNetNextStep = true;
                }
                for (int i = 0; i < 15; i++)
                {
                    for (int j = 0; j < 15; j++)
                    {
                        if (m_nNetStepdatas[i][j][1] == m_nNetSteps)
                        {
                            m_nNetStepdatas[i][j][0] = 0;
                            m_nNetStepdatas[i][j][1] = 0;
                            m_nNetSteps--;
                            chessA = i;
                            chessB = j;
                            QString senddata = QString("toundobang@%1 %2 1 1 %3 %4 0 0").arg(m_usrdata.room).arg(m_usrdata.usrname).arg(chessA).arg(chessB);
                            tcpsocket->write(senddata.toUtf8().data());
                            //qDebug() << "toundobang:" << senddata;
                            update();
                            return ;
                        }
                    }
                }
            }
            else    // '我'已下子，需悔两子
            {
                if (m_nNetSteps >= 2)
                {
                    int chessA, chessB, chessC, chessD;
                    bool exit = false;
                    for (int i = 0; i < 15; i++)
                    {
                        for (int j = 0; j < 15; j++)
                        {
                            if (m_nNetStepdatas[i][j][1] == m_nNetSteps)
                            {
                                //qDebug() << "m_nNetSteps1 = " << m_nNetSteps;
                                m_nNetStepdatas[i][j][0] = 0;
                                m_nNetStepdatas[i][j][1] = 0;
                                m_nNetSteps--;
                                chessA = i;
                                chessB = j;
                                exit = true;
                                break;
                            }
                        }
                        if (exit == true)
                        {
                            break;
                        }
                    }
                    for (int i = 0; i < 15; i++)
                    {
                        for (int j = 0; j < 15; j++)
                        {
                            if (m_nNetStepdatas[i][j][1] == m_nNetSteps)
                            {
                                //qDebug() << "m_nNetSteps2 = " << m_nNetSteps;
                                chessC = i;
                                chessD = j;
                                m_nNetStepdatas[i][j][0] = 0;
                                m_nNetStepdatas[i][j][1] = 0;
                                m_nNetSteps--;
                                QString senddata = QString("toundobang@%1 %2 1 2 %3 %4 %5 %6").arg(m_usrdata.room).arg(m_usrdata.usrname).arg(chessA).arg(chessB).arg(chessC).arg(chessD);
                                tcpsocket->write(senddata.toUtf8().data());
                                //qDebug() << "toundobang:" << senddata;
                                update();
                                return ;
                            }
                        }
                    }
                }
            }
        }
        else  // 不同意悔棋
        {
            QString senddata = QString("toundobang@%1 %2 0 0 0 0 0 0").arg(m_nroomsnum).arg(m_usrdata.usrname);
            tcpsocket->write(senddata.toUtf8().data());
        }
    }
    else if (keywords == "advundobang") // 悔棋结果
    {
        QString backdata = readdata.mid(keywords.length() + 1);
        //qDebug() << "advundobang:" << backdata;
        //QString username = backdata.section(' ', 1, 1);
        int tounok = backdata.section(' ', 2, 2).toInt();
        if (tounok == 0)
        {
            QMessageBox m_r(this);
            m_r.setWindowTitle("提示");
            m_r.setText("对方不同意悔棋！");
            m_r.exec();
        }
        else
        {
            int tounnum = backdata.section(' ', 3, 3).toInt();
            int chessA, chessB, chessC, chessD;
            chessA = backdata.section(' ', 4, 4).toInt();
            chessB = backdata.section(' ', 5, 5).toInt();
            chessC = backdata.section(' ', 6, 6).toInt();
            chessD = backdata.section(' ', 7, 7).toInt();
            if (tounnum == 1)
            {
                if (m_bNetNextStep == true)
                {
                    m_bNetNextStep = false;
                }
                else
                {
                    m_bNetNextStep = true;
                }
                m_nNetStepdatas[chessA][chessB][0] = 0;
                m_nNetStepdatas[chessA][chessB][1] = 0;
                m_nNetSteps--;
                update();
            }
            else if (tounnum == 2)
            {
                m_nNetStepdatas[chessA][chessB][0] = 0;
                m_nNetStepdatas[chessA][chessB][1] = 0;
                m_nNetStepdatas[chessC][chessD][0] = 0;
                m_nNetStepdatas[chessC][chessD][1] = 0;
                m_nNetSteps--;
                m_nNetSteps--;
                update();
            }
        }
    }
    else if (keywords == "advdraw") // 平局通知
    {
        //qDebug() << "advundo";
        QMessageBox m_r(this);
        //m_r.setWindowTitle("提示");
        //m_r.setText("对方请求悔棋！");
        QMessageBox::StandardButton m_infor = m_r.information(NULL, "平局", "对方请求平局", QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
        if (m_infor == QMessageBox::Yes)  // 同意平局
        {
            QString senddata = QString("todrawbang@%1 %2 1").arg(m_usrdata.room).arg(m_usrdata.usrname);
            //qDebug() << "todrawbang:" << senddata;
            tcpsocket->write(senddata.toUtf8().data());
        }
        else  // 不同意平局
        {
            QString senddata = QString("todrawbang@%1 %2 0").arg(m_usrdata.room).arg(m_usrdata.usrname);
            //qDebug() << "todrawbang send:" << senddata;
            tcpsocket->write(senddata.toUtf8().data());
        }
    }
    else if (keywords == "advdrawbang")
    {
        QString backdata = readdata.mid(keywords.length() + 1);
        //qDebug() << "advdrawbang read:" << backdata;
        int tounok = backdata.section(' ', 2, 2).toInt();
        if (tounok == 0)
        {
            QMessageBox m_r(this);
            m_r.setWindowTitle("提示");
            m_r.setText("对方不同意和棋！");
            m_r.exec();
        }
        else
        {
            m_nNetOutcome = 3;
            Netgameoverdatainit();
            update();
        }
    }
    else if (keywords == "advconcedebang")
    {
        QString username = readdata.mid(keywords.length() + 1);
        if (username == m_sroomuser[0])
        {
            if (m_nroomusr[0] == 1)
            {
                m_nNetOutcome = 5;
            }
            else
            {
                m_nNetOutcome = 4;
            }
        }
        else
        {
            if (m_nroomusr[0] == 1)
            {
                m_nNetOutcome = 4;
            }
            else
            {
                m_nNetOutcome = 5;
            }
        }
        Netgameoverdatainit();
        update();
    }
}

// 定时器程序
void Gobang::RunTimer()
{
    //软件打开累计时间计算
    m_nRunTimems++;
    if (m_bNetCallover == true) // 100ms
    {
        QString senddata = QString("overbang@%1 %2").arg(m_usrdata.room).arg(m_nNetOutcome);
        tcpsocket->write(senddata.toUtf8().data());//发送棋子信息
        m_bNetCallover = false;
    }
    if (m_nRunTimems >= 10)
    {
        m_nRunTimems = 0;
        m_nRunTimes++;
        if (m_nRunTimes >= 3600)
        {
            m_nRunTimes = 0;
            m_nRunTimeh++;
        }
        //每过一秒便执行
        if (m_nUInum == 31)
        {
            QString senddata = QString("viewrooms@%1").arg(m_nroomsnum);
            char *sendchar = senddata.toUtf8().data();
            tcpsocket->write(sendchar);//发送信息
        }

        if (m_nRunTimes % 4 == 0)//每四秒执行
        {
            if (m_bTCPstate == false)
            {
                QString ip = QString(TCPSERVICE_IP);
                qint16 port = PORT;
                tcpsocket->connectToHost(QHostAddress(ip), port);//连接服务器
            }
        }
    }
}

// 画图程序
void Gobang::paintEvent(QPaintEvent *event)
{
    //15*15
    QPainter p(this);
    QPen pen;

    //棋盘线宽
    pen.setWidth(2);
    pen.setColor(Qt::black);

    p.setPen(pen);

    //背景图
    p.drawPixmap(0, 0, width(), height(), QPixmap("beijing.jpg"));

    if (m_nUInum == 4)   //线下人人
    {
        //棋盘
        for (int i = 50; i <= 610; i = i+40)
        {
            p.drawLine(i, 50, i, 610);
            p.drawLine(50, i, 610, i);
        }
        p.setBrush(QBrush(Qt::black));
        p.drawEllipse(QPointF(170, 170), 4, 4);
        p.drawEllipse(QPointF(490, 170), 4, 4);
        p.drawEllipse(QPointF(170, 490), 4, 4);
        p.drawEllipse(QPointF(490, 490), 4, 4);
        p.drawEllipse(QPointF(330, 330), 4, 4);
    }
    else if (m_nUInum == 31)//经典模式选择房间界面
    {
        pen.setColor(Qt::gray);
        p.setPen(pen);
        //p.drawLine(50, 50, 610, 50);
        p.drawLine(50, 230, 610, 230);
        p.drawLine(50, 410, 610, 410);
        //p.drawLine(50, 590, 610, 590);

        //p.drawLine(50, 50, 50, 590);
        //p.drawLine(190, 50, 190, 590);
        //p.drawLine(330, 50, 330, 590);
        //p.drawLine(470, 50, 470, 590);
        //p.drawLine(610, 50, 610, 590);

        p.drawPixmap(85, 105, 70, 70, QPixmap("gobang_1.bmp"));
        p.drawPixmap(225, 105, 70, 70, QPixmap("gobang_1.bmp"));
        p.drawPixmap(365, 105, 70, 70, QPixmap("gobang_1.bmp"));
        p.drawPixmap(505, 105, 70, 70, QPixmap("gobang_1.bmp"));
        p.drawPixmap(85, 285, 70, 70, QPixmap("gobang_1.bmp"));
        p.drawPixmap(225, 285, 70, 70, QPixmap("gobang_1.bmp"));
        p.drawPixmap(365, 285, 70, 70, QPixmap("gobang_1.bmp"));
        p.drawPixmap(505, 285, 70, 70, QPixmap("gobang_1.bmp"));
        p.drawPixmap(85, 465, 70, 70, QPixmap("gobang_1.bmp"));
        p.drawPixmap(225, 465, 70, 70, QPixmap("gobang_1.bmp"));
        p.drawPixmap(365, 465, 70, 70, QPixmap("gobang_1.bmp"));
        p.drawPixmap(505, 465, 70, 70, QPixmap("gobang_1.bmp"));
        for (int j = 0; j < 3; j++)
        {
            for (int i = 0; i < 4; i++)
            {
                label_rooms[(4*j+i)*3].setText(QString("%1桌").arg(4*j+i+1));
            }
        }
    }
    else if (m_nUInum == 32)//娱乐模式选择模式
    {

    }
    else if (m_nUInum == 33)//经典模式进入房间（需要棋盘）
    {
        //棋盘
        for (int i = 50; i <= 610; i = i+40)
        {
            p.drawLine(i, 50, i, 610);
            p.drawLine(50, i, 610, i);
        }
        p.setBrush(QBrush(Qt::black));
        p.drawEllipse(QPointF(170, 170), 4, 4);
        p.drawEllipse(QPointF(490, 170), 4, 4);
        p.drawEllipse(QPointF(170, 490), 4, 4);
        p.drawEllipse(QPointF(490, 490), 4, 4);
        p.drawEllipse(QPointF(330, 330), 4, 4);
    }
    else
    {
        if (m_nUInum != 90 && m_nUInum != 91)
        {
            p.setFont(font_30);
            p.setPen(Qt::blue);
            p.drawText(250, 340, GOBANGNAME);
        }
        if (m_nUInum == 3)
        {
            /*
            if (m_bTCPstate == false)
            {
                p.setFont(font_24);
                p.setPen(Qt::blue);
                p.drawText(250, 540, "未能连上服务器");
            }*/
        }
    }


    //木板
    //p.drawPixmap(660, 0, 200, 180, QPixmap("board1.png"));

    //木板图片
    p.drawPixmap(660, 300, 200, 230, QPixmap("board2.png"));//../Image/
    p.drawPixmap(660, 450, 200, 170, QPixmap("board4.png"));
    p.drawPixmap(660, 400, 200, 80, QPixmap("board3.png"));
    p.drawPixmap(660, 500, 200, 80, QPixmap("board3.png"));


    //画棋子
    if (m_nUInum == 4)   // 线下人人模式
    {
        //棋子
        if (m_nSteps > 0)
        {
            for (int i = 0; i < 15; i++)
            {
                for (int j = 0; j < 15; j++)
                {
                    if (m_nStepdatas[i][j][0] == 1)//黑棋
                    {
                        p.drawPixmap(30 + i*40, 30 + j*40, 40, 40, QPixmap("black.png"));
                        //qDebug() << g_nSteps;
                    }
                    else if (m_nStepdatas[i][j][0] == 2)//白棋
                    {
                        p.drawPixmap(30 + i*40, 30 + j*40, 40, 40, QPixmap("write.png"));
                    }
                    if (m_nStepdatas[i][j][1] == m_nSteps)
                    {
                        pen.setWidth(2);
                        pen.setColor(Qt::red);
                        p.setPen(pen);
                        p.drawLine(50 + 40 * i - 10, 50 + 40 * j, 50 + 40 * i - 4, 50 + 40 * j);
                        p.drawLine(50 + 40 * i + 4, 50 + 40 * j, 50 + 40 * i + 10, 50 + 40 * j);
                        p.drawLine(50 + 40 * i, 50 + 40 * j - 10, 50 + 40 * i, 50 + 40 * j - 4);
                        p.drawLine(50 + 40 * i, 50 + 40 * j + 4, 50 + 40 * i, 50 + 40 * j + 10);
                    }
                }
            }
        }
        if (m_nOutcome == 1)
        {
            p.setFont(font_30);
            p.setPen(Qt::red);
            p.drawText(280, 340, "黑棋胜");
        }
        else if (m_nOutcome == 2)
        {
            p.setFont(font_30);
            p.setPen(Qt::red);
            p.drawText(280, 340, "白棋胜");
        }
        else if (m_nOutcome == 3)
        {
            p.setFont(font_30);
            p.setPen(Qt::red);
            p.drawText(285, 340, "和棋");
        }
        else if (m_nOutcome == 0 && m_nUInum == 4)
        {
            if (m_bmovestate == true)
            {
                if (m_nStepdatas[m_nmoveX][m_nmoveY][0] == 0)
                {
                    pen.setColor(Qt::red);
                    p.setPen(pen);
                    p.drawLine(50 + 40 * m_nmoveX - 10, 50 + 40 * m_nmoveY - 5, 50 + 40 * m_nmoveX - 5, 50 + 40 * m_nmoveY - 5);
                    p.drawLine(50 + 40 * m_nmoveX - 5, 50 + 40 * m_nmoveY - 10, 50 + 40 * m_nmoveX - 5, 50 + 40 * m_nmoveY - 5);
                    p.drawLine(50 + 40 * m_nmoveX + 5, 50 + 40 * m_nmoveY - 5, 50 + 40 * m_nmoveX + 10, 50 + 40 * m_nmoveY - 5);
                    p.drawLine(50 + 40 * m_nmoveX + 5, 50 + 40 * m_nmoveY - 10, 50 + 40 * m_nmoveX + 5, 50 + 40 * m_nmoveY - 5);
                    p.drawLine(50 + 40 * m_nmoveX - 10, 50 + 40 * m_nmoveY + 5, 50 + 40 * m_nmoveX - 5, 50 + 40 * m_nmoveY + 5);
                    p.drawLine(50 + 40 * m_nmoveX - 5, 50 + 40 * m_nmoveY + 5, 50 + 40 * m_nmoveX - 5, 50 + 40 * m_nmoveY + 10);
                    p.drawLine(50 + 40 * m_nmoveX + 5, 50 + 40 * m_nmoveY + 5, 50 + 40 * m_nmoveX + 5, 50 + 40 * m_nmoveY + 10);
                    p.drawLine(50 + 40 * m_nmoveX + 5, 50 + 40 * m_nmoveY + 5, 50 + 40 * m_nmoveX + 10, 50 + 40 * m_nmoveY + 5);
                    //m_nmoveX   m_nmoveY
                }
            }
        }
    }
    else if (m_nUInum == 33)//画棋子   // 线上人人经典模式
    {
        //qDebug() << "netsteps = " << m_nNetSteps;
        if (m_nNetSteps > 0)
        {
            //qDebug() << "OK3";
            for (int i = 0; i < 15; i++)
            {
                for (int j = 0; j < 15; j++)
                {
                    if (m_nNetStepdatas[i][j][0] == 1)//黑棋
                    {
                        p.drawPixmap(30 + i*40, 30 + j*40, 40, 40, QPixmap("black.png"));
                        //qDebug() << "1";
                    }
                    else if (m_nNetStepdatas[i][j][0] == 2)//白棋
                    {
                        p.drawPixmap(30 + i*40, 30 + j*40, 40, 40, QPixmap("write.png"));
                        //qDebug() << "2";
                    }
                    if (m_nNetStepdatas[i][j][1] == m_nNetSteps)
                    {
                        pen.setWidth(2);
                        pen.setColor(Qt::red);
                        p.setPen(pen);
                        p.drawLine(50 + 40 * i - 10, 50 + 40 * j, 50 + 40 * i - 4, 50 + 40 * j);
                        p.drawLine(50 + 40 * i + 4, 50 + 40 * j, 50 + 40 * i + 10, 50 + 40 * j);
                        p.drawLine(50 + 40 * i, 50 + 40 * j - 10, 50 + 40 * i, 50 + 40 * j - 4);
                        p.drawLine(50 + 40 * i, 50 + 40 * j + 4, 50 + 40 * i, 50 + 40 * j + 10);
                    }
                }
            }
        }
        if (m_nNetOutcome == 1)
        {
            p.setFont(font_30);
            p.setPen(Qt::red);
            p.drawText(280, 340, "黑棋胜");
        }
        else if (m_nNetOutcome == 2)
        {
            p.setFont(font_30);
            p.setPen(Qt::red);
            p.drawText(280, 340, "白棋胜");
        }
        else if (m_nNetOutcome == 3)
        {
            p.setFont(font_30);
            p.setPen(Qt::red);
            p.drawText(285, 340, "和棋");
        }
        else if (m_nNetOutcome == 4)
        {
            p.setFont(font_30);
            p.setPen(Qt::red);
            p.drawText(260, 340, "白棋认输，黑棋胜");
        }
        else if (m_nNetOutcome == 5)
        {
            p.setFont(font_30);
            p.setPen(Qt::red);
            p.drawText(260, 340, "黑棋认输，白棋胜");
        }
        else if (m_nNetOutcome == 0 && m_nUInum == 33)
        {
            if (m_bmovestate == true)
            {
                if (m_nNetStepdatas[m_nmoveX][m_nmoveY][0] == 0)
                {
                    pen.setColor(Qt::red);
                    p.setPen(pen);
                    p.drawLine(50 + 40 * m_nmoveX - 10, 50 + 40 * m_nmoveY - 5, 50 + 40 * m_nmoveX - 5, 50 + 40 * m_nmoveY - 5);
                    p.drawLine(50 + 40 * m_nmoveX - 5, 50 + 40 * m_nmoveY - 10, 50 + 40 * m_nmoveX - 5, 50 + 40 * m_nmoveY - 5);
                    p.drawLine(50 + 40 * m_nmoveX + 5, 50 + 40 * m_nmoveY - 5, 50 + 40 * m_nmoveX + 10, 50 + 40 * m_nmoveY - 5);
                    p.drawLine(50 + 40 * m_nmoveX + 5, 50 + 40 * m_nmoveY - 10, 50 + 40 * m_nmoveX + 5, 50 + 40 * m_nmoveY - 5);
                    p.drawLine(50 + 40 * m_nmoveX - 10, 50 + 40 * m_nmoveY + 5, 50 + 40 * m_nmoveX - 5, 50 + 40 * m_nmoveY + 5);
                    p.drawLine(50 + 40 * m_nmoveX - 5, 50 + 40 * m_nmoveY + 5, 50 + 40 * m_nmoveX - 5, 50 + 40 * m_nmoveY + 10);
                    p.drawLine(50 + 40 * m_nmoveX + 5, 50 + 40 * m_nmoveY + 5, 50 + 40 * m_nmoveX + 5, 50 + 40 * m_nmoveY + 10);
                    p.drawLine(50 + 40 * m_nmoveX + 5, 50 + 40 * m_nmoveY + 5, 50 + 40 * m_nmoveX + 10, 50 + 40 * m_nmoveY + 5);
                    //m_nmoveX   m_nmoveY
                }
            }
        }
    }
    else if (m_nUInum == 90)
    {
        p.setFont(font_20);
        p.setPen(Qt::black);
        p.drawText(140, 284, "用户名：");
        p.drawText(140, 344, "密  码：");
    }
    else if (m_nUInum == 91)
    {
        p.setFont(font_20);
        p.setPen(Qt::black);
        p.drawText(140, 284, "用户名：");
        p.drawText(140, 344, "密  码：");
        p.drawText(110, 404, "确认密码：");
    }

    //其他参数
    if (m_nUInum == 33)//进入对弈经典模式房间
    {
        p.setFont(font_20);
        p.setPen(Qt::black);
        p.drawText(680, 35, QString("%1桌").arg(m_usrdata.room));

        p.setFont(font_20);
        p.setPen(Qt::black);
        p.drawText(660, 70, m_sroomuser[0]);

        p.setFont(font_20);
        p.setPen(Qt::black);
        p.drawText(660, 180, m_sroomuser[1]);

        if (m_nroomusr[0] == 1)//执黑子
        {
            p.drawPixmap(665, 85, 50, 50, QPixmap("black.png"));//黑子
        }
        else if (m_nroomusr[0] == 2)//执白子
        {
            p.drawPixmap(665, 85, 50, 50, QPixmap("write.png"));//白子
        }

        if (m_nroomusr[1] == 1)
        {
            p.drawPixmap(665, 195, 50, 50, QPixmap("black.png"));//黑子
        }
        else if (m_nroomusr[1] == 2)
        {
            p.drawPixmap(665, 195, 50, 50, QPixmap("write.png"));//白子
        }
        /*
        if (m_nmyseat < 3)//自己为玩家
        {
            if (m_nmyseat == 1)//自己座位号1
            {
                p.setFont(font_20);
                p.setPen(Qt::black);
                p.drawText(660, 70, m_sroomuser[0]);
                if (!m_sroomuser[1].isEmpty())
                {
                    p.setFont(font_20);
                    p.setPen(Qt::black);
                    p.drawText(660, 180, m_sroomuser[1]);
                }
                if (m_nroomusr[0] == 1)//执黑子
                {
                   // if ()
                    p.drawPixmap(665, 85, 50, 50, QPixmap("black.png"));//自己为黑子
                    if (!m_sroomuser[1].isEmpty())
                    {
                        if (m_nroomusr[1] == 2)
                        {
                            p.drawPixmap(665, 195, 50, 50, QPixmap("write.png"));//对方为白子
                        }
                    }
                }
                else if (m_nroomusr[0] == 2)//执白子
                {
                    p.drawPixmap(665, 85, 50, 50, QPixmap("write.png"));//自己为白子
                    if (!m_sroomuser[1].isEmpty())
                    {
                        if (m_nroomusr[1] == 1)
                        {
                            p.drawPixmap(665, 195, 50, 50, QPixmap("black.png"));//对方为黑子
                        }
                    }
                }
            }
            else                //自己座位号2
            {
                if (!m_sroomuser[0].isEmpty())
                {
                    p.setFont(font_20);
                    p.setPen(Qt::black);
                    p.drawText(660, 70, m_sroomuser[0]);
                }
                p.setFont(font_20);
                p.setPen(Qt::black);
                p.drawText(660, 180, m_sroomuser[1]);
                if (m_nroomusr[1] == 1)//执黑子
                {
                    if (!m_sroomuser[0].isEmpty())
                    {
                        if (m_nroomusr[0] == 2)
                        {
                            p.drawPixmap(665, 85, 50, 50, QPixmap("write.png"));//对方为白子
                        }
                    }
                    p.drawPixmap(665, 195, 50, 50, QPixmap("black.png"));//自己为黑子
                }
                else if (m_nroomusr[1] == 2)//执白子
                {
                    if (!m_sroomuser[0].isEmpty())
                    {
                        if (m_nroomusr[0] == 1)
                        {
                            p.drawPixmap(665, 85, 50, 50, QPixmap("black.png"));//对方为黑子
                        }
                    }
                    p.drawPixmap(665, 195, 50, 50, QPixmap("write.png"));//自己为白子
                }
            }
        }
        else//自己为旁观者
        {

        }
        */

    }


/*
    if (g_bMoveState == true)
    {
        if (g_bNextStep == true)    //黑棋
        {
            p.drawPixmap(30 + (g_nmoveX-1)*40, 30 + (g_nmoveX-1)*40, 40, 40, QPixmap("../Image/black.png"));
        }
        else    //白棋
        {
            p.drawPixmap(30 + (g_nmoveX-1)*40, 30 + (g_nmoveY-1)*40, 40, 40, QPixmap("../Image/write.png"));
        }
    }
*/

}

// 鼠标按下
void Gobang::mousePressEvent(QMouseEvent *ev)//移动窗口
{
    if (ev->button() == Qt::RightButton)
    {
        m_pWinMove = ev->globalPos() - this->frameGeometry().topLeft();
        m_bWinMovestate = true;
    }
    else if (ev->button() == Qt::LeftButton)
    {
        if (ev->x() > 30 && ev->y() > 30 && ev->x() < 630 && ev->y() < 630);
        else if (ev->x() > 670 && ev->x() < 850 && ev->y() > 310 && ev->y() < 370);//按键A
        else if (ev->x() > 670 && ev->x() < 850 && ev->y() > 410 && ev->y() < 470);//按键B
        else if (ev->x() > 670 && ev->x() < 850 && ev->y() > 510 && ev->y() < 570);//按键C
        else
        {
            m_pWinMove = ev->globalPos() - this->frameGeometry().topLeft();
            m_bWinMovestate = true;
        }
    }
}

/*
 * m_nUInum:
 * 1. 主界面
 * 2. 单机模式界面
 * 3. 联机登录界面
 * 4. 个人单机游戏
 * 5. 电脑AI
 * 6. AI对战
 * 7. 残局破解
 *
 * 30.
 *
 * 90. 登录界面
 * 91. 注册界面
 *
 * 1 -> 2 -> 4                 √
 *        -> 5 -> 6
 *             -> 7
 *   -> 3 ->90 -> 30 -> 31 -> 33
 *                   -> 32
 *             -> /
 *        ->91 -> 90           √
 *             -> 90           √
 *
 * 主界面 -> 单机模式界面 -> 单人游戏                      √
 *                     -> 电脑AI  -> AI对战
 *                               -> 残局破解
 *       -> 联机登录界面 -> 登录    -> 联机主界面 -> 经典模式 -> 进入房间游戏
 *                                           -> 娱乐模式
 *                               -> （提示窗口）
 *                     -> 注册    -> 注册成功转登录       √
 *                               -> 已有账号转登录       √
*/

// 鼠标松开
void Gobang::mouseReleaseEvent(QMouseEvent *ev)
{
    m_bWinMovestate = false;
    if (ev->button() == Qt::LeftButton)
    {
        if (m_nUInum == 1)//主界面
        {
            if (ev->x() > 670 && ev->x() < 850 && ev->y() > 310 && ev->y() < 370)//按键A
            {
                m_nUInum = 2;
                label_btnA.setText("自由对战");
                label_btnB.setText("电脑 AI");
                label_btnC.setText("返    回");
            }
            else if (ev->x() > 670 && ev->x() < 850 && ev->y() > 410 && ev->y() < 470)//按键B
            {
                if (m_usrdata.usrname.isEmpty())
                {
                    m_nUInum = 3;
                    label_btnA.setText("登    录");
                    label_btnB.setText("注    册");
                    label_btnC.setText("返    回");
                }
                else
                {
                    m_lloginname->hide();
                    m_lloginpass->hide();
                    m_lloginpasses->hide();

                    m_nUInum = 30;
                    label_btnA.setText("经典模式");
                    label_btnB.setText("娱乐模式");
                    label_btnC.setText("返    回");
                }
            }
            else if (ev->x() > 670 && ev->x() < 850 && ev->y() > 510 && ev->y() < 570)//按键C
            {
                close();
            }
        }
        else if (m_nUInum == 2)//单机模式界面
        {
            if (ev->x() > 670 && ev->x() < 850 && ev->y() > 310 && ev->y() < 370)//按键A
            {
                m_nUInum = 4;
                label_btnA.setText("悔    棋");
                label_btnB.setText("重新开局");
                label_btnC.setText("返    回");
            }
            else if (ev->x() > 670 && ev->x() < 850 && ev->y() > 410 && ev->y() < 470)//按键B
            {
                m_nUInum = 5;
                label_btnA.setText("AI 对战");
                label_btnB.setText("残局破解");
                label_btnC.setText("返    回");

            }
            else if (ev->x() > 670 && ev->x() < 850 && ev->y() > 510 && ev->y() < 570)//按键C
            {
                m_nUInum = 1;
                label_btnA.setText("单机模式");
                label_btnB.setText("联机模式");
                label_btnC.setText("退    出");
            }
        }
        else if (m_nUInum == 3)//联机登录界面
        {
            if (ev->x() > 670 && ev->x() < 850 && ev->y() > 310 && ev->y() < 370)//按键A
            {
                m_nUInum = 90;//登录
                m_lloginname->setText("");
                m_lloginpass->setText("");
                m_lloginpasses->setText("");
                label_btnA.setText("登    录");
                label_btnB.setText("忘记密码");
                label_btnC.setText("返    回");
                m_lloginname->show();
                m_lloginpass->show();
                m_lloginpasses->hide();
            }
            else if (ev->x() > 670 && ev->x() < 850 && ev->y() > 410 && ev->y() < 470)//按键B
            {
                m_nUInum = 91;//注册
                m_lloginname->setText("");
                m_lloginpass->setText("");
                m_lloginpasses->setText("");
                label_btnA.setText("注    册");
                label_btnB.setText("已有账号");
                label_btnC.setText("返    回");
                m_lloginname->show();
                m_lloginpass->show();
                m_lloginpasses->show();
            }
            else if (ev->x() > 670 && ev->x() < 850 && ev->y() > 510 && ev->y() < 570)//按键C
            {
                m_nUInum = 1;
                label_btnA.setText("单机模式");
                label_btnB.setText("联机模式");
                label_btnC.setText("退    出");
            }
        }
        else if (m_nUInum == 4)//单机游戏
        {
            if (ev->x() > 30 && ev->y() > 30 && ev->x() < 630 && ev->y() < 630)//落子
            {
                int x0 = ev->x()-30;
                int y0 = ev->y()-30;

                int i = x0/40;
                int j = y0/40;

                if (m_nStepdatas[i][j][0] == 0)//判断是否已落子
                {
                    if (m_nOutcome == 0)//判断比赛是否结束
                    {
                        m_nSteps++;
                        if (m_bNextStep == true)
                        {
                            m_nStepdatas[i][j][0] = 1;//黑子为1
                            m_bNextStep = false;
                        }
                        else
                        {
                            m_nStepdatas[i][j][0] = 2;//白子为2
                            m_bNextStep = true;
                        }
                        m_nStepdatas[i][j][1] = m_nSteps;
                        JudgeOutcome();
                        update();
                    }
                }
            }
            else if (ev->x() > 670 && ev->x() < 850 && ev->y() > 310 && ev->y() < 370)//悔棋
            {
                if (m_nSteps > 0)//判断是否有棋子
                {
                    if (m_nOutcome == 0)//判断比赛是否结束
                    {
                        if (m_bNextStep == true)
                        {
                            m_bNextStep = false;
                        }
                        else
                        {
                            m_bNextStep = true;
                        }
                        for (int i = 0; i < 15; i++)
                        {
                            for (int j = 0; j < 15; j++)
                            {
                                if (m_nStepdatas[i][j][1] == m_nSteps)
                                {
                                    m_nStepdatas[i][j][0] = 0;
                                    m_nStepdatas[i][j][1] = 0;
                                    m_nSteps--;
                                    update();
                                    return ;
                                }
                            }
                        }
                    }
                }
            }
            else if (ev->x() > 670 && ev->x() < 850 && ev->y() > 410 && ev->y() < 470)//重新开局
            {
                for (int i = 0; i < 15; i++)
                {
                    for (int j = 0; j < 15; j++)
                    {
                        m_nStepdatas[i][j][0] = 0;
                        m_nStepdatas[i][j][1] = 0;
                    }
                }
                m_nSteps = 0;
                m_nOutcome = 0;
                if (m_bFristStep == true)
                {
                    m_bFristStep = false;
                    m_bNextStep = false;
                }
                else
                {
                    m_bFristStep = true;
                    m_bNextStep = true;
                }
                update();
            }
            else if (ev->x() > 670 && ev->x() < 850 && ev->y() > 510 && ev->y() < 570)//按键C
            {
                m_nUInum = 2;
                label_btnA.setText("自由对战");
                label_btnB.setText("电脑 AI");
                label_btnC.setText("返    回");
            }
        }
        else if (m_nUInum == 5)//电脑AI
        {
            if (ev->x() > 670 && ev->x() < 850 && ev->y() > 310 && ev->y() < 370)//按键A
            {
                QMessageBox m_r(this);
                m_r.setWindowTitle("提示");
                m_r.setText("功能开发中，敬请期待！");
                m_r.exec();
            }
            else if (ev->x() > 670 && ev->x() < 850 && ev->y() > 410 && ev->y() < 470)//按键B
            {
                QMessageBox m_r(this);
                m_r.setWindowTitle("提示");
                m_r.setText("功能开发中，敬请期待！");
                m_r.exec();
            }
            else if (ev->x() > 670 && ev->x() < 850 && ev->y() > 510 && ev->y() < 570)//按键C
            {
                m_nUInum = 2;
                label_btnA.setText("自由对战");
                label_btnB.setText("电脑 AI");
                label_btnC.setText("返    回");

            }
        }
        else if (m_nUInum == 30)//联机模式主界面
        {
            if (ev->x() > 670 && ev->x() < 850 && ev->y() > 310 && ev->y() < 370)//按键A
            {
                m_nUInum = 31;
                label_btnA.setText("创建房间");
                label_btnB.setText("");
                label_btnC.setText("返    回");
                for (int i = 0; i < 36; i++)
                {
                    label_rooms[i].show();
                }
                QString senddata = QString("viewrooms@%1").arg(m_nroomsnum);
                char *sendchar = senddata.toUtf8().data();
                tcpsocket->write(sendchar);//发送信息
            }
            else if (ev->x() > 670 && ev->x() < 850 && ev->y() > 410 && ev->y() < 470)//按键B
            {
                m_nUInum = 32;
                label_btnA.setText("");
                label_btnB.setText("");
                label_btnC.setText("返    回");
            }
            else if (ev->x() > 670 && ev->x() < 850 && ev->y() > 510 && ev->y() < 570)//按键C
            {
                m_nUInum = 1;
                label_btnA.setText("单机模式");
                label_btnB.setText("联机模式");
                label_btnC.setText("退    出");
            }
        }
        else if (m_nUInum == 31)//在线对弈选择房间界面
        {
            for (int j = 0; j < 3; j++)//是否为选择房间
            {
                for (int i = 0; i < 4; i++)
                {
                    int xleft = 85 + 140*i;
                    int xright = 155 + 140*i;
                    int yup = 105 + 180*j;
                    int ydown = 175 + 180*j;

                    if (ev->x() > xleft && ev->x() < xright && ev->y() > yup && ev->y() < ydown)
                    {
                        //qDebug() << "xleft=" << xleft << ", xright=" << xright << ", yup=" << yup << ", ydown=" << ydown;
                        //qDebug() << "OK4";
                        //qDebug() << "x=" << ev->x() << ", y=" << ev->y();
                        //qDebug() << "i=" << i << ", j=" << j;
                        int roomnum = 4*j+i+1+12*(m_nroomsnum-1);
                        //qDebug() << "room:" << roomnum;
                        QString senddata = QString("goroom@%1 %2").arg(m_usrdata.usrname).arg(roomnum);
                        tcpsocket->write(senddata.toUtf8().data());//发送进入房间信息
                    }
                }
            }
            if (ev->x() > 670 && ev->x() < 850 && ev->y() > 310 && ev->y() < 370)//按键A
            {

            }
            else if (ev->x() > 670 && ev->x() < 850 && ev->y() > 410 && ev->y() < 470)//按键B
            {

            }
            else if (ev->x() > 670 && ev->x() < 850 && ev->y() > 510 && ev->y() < 570)//按键C
            {
                m_nUInum = 30;
                label_btnA.setText("经典模式");
                label_btnB.setText("娱乐模式");
                label_btnC.setText("返    回");
                for (int i = 0; i < 36; i++)
                {
                    label_rooms[i].hide();
                }
            }
        }
        else if (m_nUInum == 32)//娱乐模式界面
        {
            if (ev->x() > 670 && ev->x() < 850 && ev->y() > 310 && ev->y() < 370)//按键A
            {
            }
            else if (ev->x() > 670 && ev->x() < 850 && ev->y() > 410 && ev->y() < 470)//按键B
            {
            }
            else if (ev->x() > 670 && ev->x() < 850 && ev->y() > 510 && ev->y() < 570)//按键C
            {
                m_nUInum = 30;
                label_btnA.setText("经典模式");
                label_btnB.setText("娱乐模式");
                label_btnC.setText("返    回");
            }
        }
        else if (m_nUInum == 33)//在线对弈经典模式界面
        {
            if (m_usrdata.place == 1 || m_usrdata.place == 2)   // 如果自己为当局者
            {
                if (m_bNetStartgame == false)  // 当游戏还没有开始(准备)
                {
                    if (ev->x() > 670 && ev->x() < 850 && ev->y() > 310 && ev->y() < 370)//按键A
                    {
                        if (m_usrdata.place == 1 || m_usrdata.place == 2)   // 如果自己为当局者
                        {
                            qDebug() << "readysend ok1";
                            qDebug() << "usrplece:" << m_usrdata.place;
                            qDebug() << "zhunbei:" << m_nroomusr[m_usrdata.place - 1];
                            if (m_nroomusr[m_usrdata.place - 1] == 0)  //当自己没有准备
                            {
                                QString senddata;
                                if (m_usrdata.place == 1)
                                {
                                    if (m_bNetFristStep == true)
                                    {
                                        senddata = QString("ready@%1 %2 1").arg(m_usrdata.room).arg(m_usrdata.usrname);
                                    }
                                    else
                                    {
                                        senddata = QString("ready@%1 %2 2").arg(m_usrdata.room).arg(m_usrdata.usrname);
                                    }
                                }
                                else if (m_usrdata.place == 2)
                                {
                                    if (m_bNetFristStep == true)
                                    {
                                        senddata = QString("ready@%1 %2 1").arg(m_usrdata.room).arg(m_usrdata.usrname);
                                    }
                                    else
                                    {
                                        senddata = QString("ready@%1 %2 2").arg(m_usrdata.room).arg(m_usrdata.usrname);
                                    }
                                }
                                qDebug() << "readysend senddata:" << senddata;
                                //qDebug() << "myfirststep = " << m_bNetFristStep;
                                //qDebug() << "readydata:" << senddata;
                                //m_nroomusr[m_usrdata.place - 1] = 1;
                                tcpsocket->write(senddata.toUtf8().data());//发送准备信息
                            }
                            else if (m_nroomusr[m_usrdata.place - 1] != 0)   //当自己已经准备
                            {
                                QString senddata;
                                if (m_usrdata.place == 1)
                                {
                                    senddata = QString("ready@%1 %2 0").arg(m_usrdata.room).arg(m_usrdata.usrname);
                                }
                                else if (m_usrdata.place == 2)
                                {
                                    senddata = QString("ready@%1 %2 0").arg(m_usrdata.room).arg(m_usrdata.usrname);
                                }
                                //qDebug() << "disready send data:" << senddata;
                                //m_nroomusr[m_usrdata.place - 1] = 1;
                                tcpsocket->write(senddata.toUtf8().data());//发送准备信息（取消准备
                            }
                        }
                        //update();
                    }
                    else if (ev->x() > 670 && ev->x() < 850 && ev->y() > 410 && ev->y() < 470)//按键B
                    {
                    }
                    else if (ev->x() > 670 && ev->x() < 850 && ev->y() > 510 && ev->y() < 570)//按键C
                    {
                        m_nUInum = 31;
                        label_btnA.setText("创建房间");
                        label_btnB.setText("");
                        label_btnC.setText("返    回");
                        QString senddata = QString("outroom@%1 %2").arg(m_usrdata.usrname).arg(m_nroomsnum);
                        char *sendchar = senddata.toUtf8().data();
                        tcpsocket->write(sendchar);//发送信息
                        m_nNetSteps = 0;
                        m_nNetOutcome = 0;
                        for (int i = 0; i< 15; i++)
                        {
                            for (int j = 0; j < 15; j++)
                            {
                                m_nNetStepdatas[i][j][0] = 0;
                                m_nNetStepdatas[i][j][1] = 0;
                            }
                        }
                    }
                }
                else  // 当游戏已经开始(悔棋)
                {
                    if (ev->x() > 30 && ev->y() > 30 && ev->x() < 630 && ev->y() < 630)  // 落子
                    {
                        if (m_bNetFristStep == m_bNetNextStep)  // 判断是否为自己执棋
                        {
                            int x0 = ev->x()-30;
                            int y0 = ev->y()-30;

                            int i = x0/40;
                            int j = y0/40;

                            if (m_nNetStepdatas[i][j][0] == 0)//判断是否已落子
                            {
                                if (m_nNetOutcome == 0)//判断比赛是否结束
                                {
                                    m_nNetSteps++;
                                    if (m_bNetNextStep == true)
                                    {
                                        m_nNetStepdatas[i][j][0] = 1;//黑子为1
                                        m_bNetNextStep = false;
                                    }
                                    else
                                    {
                                        m_nNetStepdatas[i][j][0] = 2;//白子为2
                                        m_bNetNextStep = true;
                                    }
                                    m_nNetStepdatas[i][j][1] = m_nNetSteps;
                                    QString senddata = QString("gobang@%1 %2 %3,%4,%5").arg(m_usrdata.room).arg(m_usrdata.usrname).arg(i).arg(j).arg(m_nNetStepdatas[i][j][0]);
                                    tcpsocket->write(senddata.toUtf8().data());//发送棋子信息
                                    NetOutcome();   // 检查比赛是否已经结束
                                    if (m_nNetOutcome != 0) // 下棋者给服务器反馈
                                    {
                                        m_bNetCallover = true;
                                    }
                                }
                            }
                        }
                    }
                    else if (ev->x() > 670 && ev->x() < 850 && ev->y() > 310 && ev->y() < 370)  // 悔棋
                    {
                        if (m_usrdata.place <= 2)
                        {
                            if (m_nNetSteps > 0)//判断是否有棋子
                            {
                                if (m_nroomusr[m_usrdata.place - 1] == 2)
                                {
                                    if (m_nNetSteps <= 1)
                                    {
                                        return ;
                                    }
                                }
                                if (m_nNetOutcome == 0)//判断比赛是否结束
                                {
                                    // 发送悔棋通知
                                    QString senddata = QString("undobang@%1 %2").arg(m_usrdata.room).arg(m_usrdata.usrname);
                                    tcpsocket->write(senddata.toUtf8().data());//发送准备信息
                                    QMessageBox m_r(this);
                                    m_r.setWindowTitle("提示");
                                    m_r.setText("悔棋请求已发送！");
                                    m_r.exec();
                                }
                            }
                        }
                    }
                    else if (ev->x() > 670 && ev->x() < 850 && ev->y() > 410 && ev->y() < 470)//按键B  平局
                    {
                        if (m_usrdata.place <= 2)
                        {
                            if (m_nNetOutcome == 0)//判断比赛是否结束
                            {
                                QString senddata = QString("drawbang@%1 %2").arg(m_usrdata.room).arg(m_usrdata.usrname);
                                tcpsocket->write(senddata.toUtf8().data());//发送平局信息
                            }
                        }
                    }
                    else if (ev->x() > 670 && ev->x() < 850 && ev->y() > 510 && ev->y() < 570)//按键C  认输
                    {
                        if (m_usrdata.place <= 2)
                        {
                            if (m_nNetOutcome == 0)//判断比赛是否结束
                            {
                                QString senddata = QString("concedebang@%1 %2").arg(m_usrdata.room).arg(m_usrdata.usrname);
                                tcpsocket->write(senddata.toUtf8().data());//发送认输信息
                            }
                        }
                    }
                }
            }
            else
            {
                if (ev->x() > 670 && ev->x() < 850 && ev->y() > 510 && ev->y() < 570)//按键C
                {
                    m_nUInum = 31;
                    label_btnA.setText("创建房间");
                    label_btnB.setText("");
                    label_btnC.setText("返    回");
                    QString senddata = QString("outroom@%1 %2").arg(m_usrdata.usrname).arg(m_nroomsnum);
                    char *sendchar = senddata.toUtf8().data();
                    tcpsocket->write(sendchar);//发送信息
                    m_nNetSteps = 0;
                    m_nNetOutcome = 0;
                    for (int i = 0; i< 15; i++)
                    {
                        for (int j = 0; j < 15; j++)
                        {
                            m_nNetStepdatas[i][j][0] = 0;
                            m_nNetStepdatas[i][j][1] = 0;
                        }
                    }
                }
            }
        }
        else if (m_nUInum == 90)//登录界面
        {
            if (ev->x() > 670 && ev->x() < 850 && ev->y() > 310 && ev->y() < 370)//按键A
            {
                if (m_bTCPstate == true)
                {
                    QString namestr = m_lloginname->text();
                    QString passstr = m_lloginpass->text();
                    if ((!namestr.isEmpty()) && (!passstr.isEmpty()))
                    {
                        QString senddata = QString("login@%1 %2").arg(namestr).arg(passstr);
                        char *sendchar = senddata.toUtf8().data();
                        tcpsocket->write(sendchar);//发送登录信息
                    }
                    else
                    {
                        QMessageBox m_r(this);
                        m_r.setWindowTitle("提示");
                        m_r.setText("请输入用户名与密码！");
                        m_r.exec();
                    }
                }
                else
                {
                    QMessageBox m_r(this);
                    m_r.setWindowTitle("提示");
                    m_r.setText("未连上服务器，请检查您的网络或服务器正在维护！");
                    m_r.exec();
                }
            }
            else if (ev->x() > 670 && ev->x() < 850 && ev->y() > 410 && ev->y() < 470)//按键B
            {
                QMessageBox m_r(this);
                m_r.setWindowTitle("提示");
                m_r.setText("请将用户名以及您印象中大概的注册时间发送邮箱到下面的邮箱中，后续会有管理员进行处理。\nadpxg@foxmail.com");
                m_r.exec();
            }
            else if (ev->x() > 670 && ev->x() < 850 && ev->y() > 510 && ev->y() < 570)//按键C
            {
                m_nUInum = 3;
                label_btnA.setText("登    录");
                label_btnB.setText("注    册");
                label_btnC.setText("返    回");
                m_lloginname->hide();
                m_lloginpass->hide();
                m_lloginpasses->hide();
            }
        }
        else if (m_nUInum == 91)//注册界面
        {
            if (ev->x() > 670 && ev->x() < 850 && ev->y() > 310 && ev->y() < 370)//按键A
            {
                if (m_bTCPstate == true)
                {
                    QString namestr = m_lloginname->text();
                    QString passstr = m_lloginpass->text();
                    QString passesstr = m_lloginpasses->text();
                    //qDebug() << "name:" << namestr;
                    //qDebug() << "pass:" << passstr;
                    //qDebug() << "passes:" << passesstr;

                    if (namestr.isEmpty() || passstr.isEmpty() || passesstr.isEmpty())
                    {
                        QMessageBox m_r(this);
                        m_r.setWindowTitle("提示");
                        m_r.setText("请把内容填充完整");
                        m_r.exec();
                    }
                    else if (namestr.length() != namestr.remove(' ').length())
                    {
                        QMessageBox m_r(this);
                        m_r.setWindowTitle("提示");
                        m_r.setText("名字内请不要包含空格");
                        m_r.exec();
                    }
                    else if (passstr.length() != passstr.remove(' ').length())
                    {
                        QMessageBox m_r(this);
                        m_r.setWindowTitle("提示");
                        m_r.setText("密码内请不要包含空格");
                        m_r.exec();
                    }
                    else if (namestr == "NULL")
                    {
                        QMessageBox m_r(this);
                        m_r.setWindowTitle("提示");
                        m_r.setText("该用户名已被占用，请更改用户名");
                        m_r.exec();
                    }
                    else
                    {
                        if (passstr != passesstr)
                        {
                            QMessageBox m_r(this);
                            m_r.setWindowTitle("提示");
                            m_r.setText("两次输入密码不一致！");
                            m_r.exec();
                        }
                        else
                        {
                            QString senddata = QString("register@%1 %2").arg(namestr).arg(passstr);
                            //qDebug() << "register:" << senddata << " namelength:" << namestr.length();
                            char *sendchar = senddata.toUtf8().data();
                            tcpsocket->write(sendchar);//发送注册信息
                        }
                    }
                }
                else
                {
                    QMessageBox m_r(this);
                    m_r.setWindowTitle("提示");
                    m_r.setText("未连上服务器，请检查您的网络或服务器正在维护！");
                    m_r.exec();
                }
            }
            else if (ev->x() > 670 && ev->x() < 850 && ev->y() > 410 && ev->y() < 470)//按键B
            {
                m_nUInum = 90;//登录
                m_lloginname->setText("");
                m_lloginpass->setText("");
                m_lloginpasses->setText("");
                label_btnA.setText("登    录");
                label_btnB.setText("忘记密码");
                label_btnC.setText("返    回");
                m_lloginname->show();
                m_lloginpass->show();
                m_lloginpasses->hide();
            }
            else if (ev->x() > 670 && ev->x() < 850 && ev->y() > 510 && ev->y() < 570)//按键C
            {
                m_nUInum = 3;
                label_btnA.setText("登    录");
                label_btnB.setText("注    册");
                label_btnC.setText("返    回");
                m_lloginname->hide();
                m_lloginpass->hide();
                m_lloginpasses->hide();
            }
        }
    }
    update();
}

// 鼠标移动
void Gobang::mouseMoveEvent(QMouseEvent *ev)
{
    //qDebug() << "Mouse move : x = " << ev->x() << "  y = " << ev->y();
    if (m_nUInum == 4)
    {
        //this->setCursor(QCursor(Qt::BlankCursor));//隐藏鼠标指针
        if (ev->x() > 30 && ev->y() > 30 && ev->x() < 630 && ev->y() < 630)
        {
            if (m_nOutcome == 0)
            {
                if (m_bmovestate == false)
                {
                    m_bmovestate = true;
                }
                m_nmoveX = (ev->x()-30)/40;
                m_nmoveY = (ev->y()-30)/40;
                update();
            }
        }
        else
        {
            this->setCursor(QCursor(Qt::ArrowCursor));//显示鼠标指针
            if (m_bmovestate == true)
            {
                m_bmovestate = false;
                update();
            }
        }
    }
    else if (m_nUInum == 33)
    {
        if (m_bNetStartgame == true && m_usrdata.place <= 2)  // 判断游戏是否已经开始并且自己是否为玩家
        {
            if (ev->x() > 30 && ev->y() > 30 && ev->x() < 630 && ev->y() < 630)
            {
                if (m_bNetFristStep == m_bNetNextStep)  // 判断是否为自己执棋
                {
                    if (m_nNetOutcome == 0)
                    {
                        if (m_bmovestate == false)
                        {
                            m_bmovestate = true;
                        }
                        m_nmoveX = (ev->x()-30)/40;
                        m_nmoveY = (ev->y()-30)/40;
                        update();
                    }
                }
            }
            else
            {
                this->setCursor(QCursor(Qt::ArrowCursor));//显示鼠标指针
                if (m_bmovestate == true)
                {
                    m_bmovestate = false;
                    update();
                }
            }
        }
    }

    if (m_bWinMovestate == true)
    {
        move(ev->globalPos() - m_pWinMove);
    }
}

// 判断胜负
void Gobang::JudgeOutcome()
{
    if (m_nSteps == 225)
    {
        m_nOutcome = 3;
    }
    else
    {
        for (int i = 0; i < 15; i++)
        {
            for (int j = 0; j < 11; j++)
            {
                if (m_nStepdatas[i][j][0] == 1 && m_nStepdatas[i][j+1][0] == 1 && m_nStepdatas[i][j+2][0] == 1 && m_nStepdatas[i][j+3][0] == 1 && m_nStepdatas[i][j+4][0] == 1)
                {
                    m_nOutcome = 1;
                    return ;
                }
                else if (m_nStepdatas[i][j][0] + m_nStepdatas[i][j+1][0] + m_nStepdatas[i][j+2][0] + m_nStepdatas[i][j+3][0] + m_nStepdatas[i][j+4][0] == 10)
                {
                    m_nOutcome = 2;
                    return ;
                }
            }
        }
        for (int i = 0; i < 11; i++)
        {
            for (int j = 0; j < 15; j++)
            {
                if (m_nStepdatas[i][j][0] == 1 && m_nStepdatas[i+1][j][0] == 1 && m_nStepdatas[i+2][j][0] == 1 && m_nStepdatas[i+3][j][0] == 1 && m_nStepdatas[i+4][j][0] == 1)
                {
                    m_nOutcome = 1;
                    return ;
                }
                else if (m_nStepdatas[i][j][0] + m_nStepdatas[i+1][j][0] + m_nStepdatas[i+2][j][0] + m_nStepdatas[i+3][j][0] + m_nStepdatas[i+4][j][0] == 10)
                {
                    m_nOutcome = 2;
                    return ;
                }
            }
        }
        for (int i = 0; i < 11; i++)
        {
            for (int j = 0; j < 11; j++)
            {
                if (m_nStepdatas[i][j][0] == 1 && m_nStepdatas[i+1][j+1][0] == 1 && m_nStepdatas[i+2][j+2][0] == 1 && m_nStepdatas[i+3][j+3][0] == 1 && m_nStepdatas[i+4][j+4][0] == 1)
                {
                    m_nOutcome = 1;
                    return ;
                }
                else if (m_nStepdatas[i][j][0] + m_nStepdatas[i+1][j+1][0] + m_nStepdatas[i+2][j+2][0] + m_nStepdatas[i+3][j+3][0] + m_nStepdatas[i+4][j+4][0] == 10)
                {
                    m_nOutcome = 2;
                    return ;
                }
            }
        }
        for (int i = 4; i < 15; i++)
        {
            for (int j = 0; j < 11; j++)
            {
                if (m_nStepdatas[i][j][0] == 1 && m_nStepdatas[i-1][j+1][0] == 1 && m_nStepdatas[i-2][j+2][0] == 1 && m_nStepdatas[i-3][j+3][0] == 1 && m_nStepdatas[i-4][j+4][0] == 1)
                {
                    m_nOutcome = 1;
                    return ;
                }
                else if (m_nStepdatas[i][j][0] + m_nStepdatas[i-1][j+1][0] + m_nStepdatas[i-2][j+2][0] + m_nStepdatas[i-3][j+3][0] + m_nStepdatas[i-4][j+4][0] == 10)
                {
                    m_nOutcome = 2;
                    return ;
                }
            }
        }
    }
}
void Gobang::NetOutcome()
{
    if (m_nNetSteps == 225)
    {
        m_nNetOutcome = 3;
        Netgameoverdatainit();
    }
    else
    {
        for (int i = 0; i < 15; i++)
        {
            for (int j = 0; j < 11; j++)
            {
                if (m_nNetStepdatas[i][j][0] == 1 && m_nNetStepdatas[i][j+1][0] == 1 && m_nNetStepdatas[i][j+2][0] == 1 && m_nNetStepdatas[i][j+3][0] == 1 && m_nNetStepdatas[i][j+4][0] == 1)
                {
                    m_nNetOutcome = 1;
                    Netgameoverdatainit();
                    return ;
                }
                else if (m_nNetStepdatas[i][j][0] + m_nNetStepdatas[i][j+1][0] + m_nNetStepdatas[i][j+2][0] + m_nNetStepdatas[i][j+3][0] + m_nNetStepdatas[i][j+4][0] == 10)
                {
                    m_nNetOutcome = 2;
                    Netgameoverdatainit();
                    return ;
                }
            }
        }
        for (int i = 0; i < 11; i++)
        {
            for (int j = 0; j < 15; j++)
            {
                if (m_nNetStepdatas[i][j][0] == 1 && m_nNetStepdatas[i+1][j][0] == 1 && m_nNetStepdatas[i+2][j][0] == 1 && m_nNetStepdatas[i+3][j][0] == 1 && m_nNetStepdatas[i+4][j][0] == 1)
                {
                    m_nNetOutcome = 1;
                    Netgameoverdatainit();
                    return ;
                }
                else if (m_nNetStepdatas[i][j][0] + m_nNetStepdatas[i+1][j][0] + m_nNetStepdatas[i+2][j][0] + m_nNetStepdatas[i+3][j][0] + m_nNetStepdatas[i+4][j][0] == 10)
                {
                    m_nNetOutcome = 2;
                    Netgameoverdatainit();
                    return ;
                }
            }
        }
        for (int i = 0; i < 11; i++)
        {
            for (int j = 0; j < 11; j++)
            {
                if (m_nNetStepdatas[i][j][0] == 1 && m_nNetStepdatas[i+1][j+1][0] == 1 && m_nNetStepdatas[i+2][j+2][0] == 1 && m_nNetStepdatas[i+3][j+3][0] == 1 && m_nNetStepdatas[i+4][j+4][0] == 1)
                {
                    m_nNetOutcome = 1;
                    Netgameoverdatainit();
                    return ;
                }
                else if (m_nNetStepdatas[i][j][0] + m_nNetStepdatas[i+1][j+1][0] + m_nNetStepdatas[i+2][j+2][0] + m_nNetStepdatas[i+3][j+3][0] + m_nNetStepdatas[i+4][j+4][0] == 10)
                {
                    m_nNetOutcome = 2;
                    Netgameoverdatainit();
                    return ;
                }
            }
        }
        for (int i = 4; i < 15; i++)
        {
            for (int j = 0; j < 11; j++)
            {
                if (m_nNetStepdatas[i][j][0] == 1 && m_nNetStepdatas[i-1][j+1][0] == 1 && m_nNetStepdatas[i-2][j+2][0] == 1 && m_nNetStepdatas[i-3][j+3][0] == 1 && m_nNetStepdatas[i-4][j+4][0] == 1)
                {
                    m_nNetOutcome = 1;
                    Netgameoverdatainit();
                    return ;
                }
                else if (m_nNetStepdatas[i][j][0] + m_nNetStepdatas[i-1][j+1][0] + m_nNetStepdatas[i-2][j+2][0] + m_nNetStepdatas[i-3][j+3][0] + m_nNetStepdatas[i-4][j+4][0] == 10)
                {
                    m_nNetOutcome = 2;
                    Netgameoverdatainit();
                    return ;
                }
            }
        }
    }

}

// 游戏结束部分数据初始化
void Gobang::Netgameoverdatainit()
{
    if (m_nNetOutcome != 0)
    {
        m_nroomusr[0] = 0;
        m_nroomusr[1] = 0;

        m_bNetStartgame = false;

        if (m_usrdata.place <= 2)  // 自己为玩家
        {
            if (m_bNetFristStep == true)
            {
                m_bNetFristStep = false;
            }
            else
            {
                m_bNetFristStep = true;
            }
            m_bNetNextStep = true;
            label_btnA.setText("准    备");
            label_btnB.setText("");
            label_btnC.setText("退出房间");
        }
        update();
    }
}
